package com.ljx.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Company: 上海数惠系统技术有限公司
 * Department: 数据中心：研发二部
 * Date: 2021/04/11 14:19
 *
 * @Author: Ljxpa
 * Email: lujx@dist.com.cn
 * Desc:
 */
public class DatasourceContextHolder {
	private static Logger log = LoggerFactory.getLogger(DatasourceContextHolder.class);
	//线程本地环境
	private static final ThreadLocal<DatasourceTypeEnum> local = new ThreadLocal<DatasourceTypeEnum>();
	public static void setReadOrWrite(DatasourceTypeEnum readOrWrite) {
		local.set(readOrWrite);
		log.info("数据库切换到" + readOrWrite + "库.");
	}

	public static DatasourceTypeEnum getReadOrWrite() {
		return local.get();
	}

	public static void clearLocal() {
		local.remove();
	}
}
